package com.example.aoppost;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Date 2022/1/27
 * @Created by Jonathan
 */
//@Component
@SuppressWarnings({"rawtypes", "unchecked"}) // ---> 注意这个解决方法
public class MyAopAspectJPostProcessor implements BeanPostProcessor {

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		return Proxy.newProxyInstance(MyAopAspectJPostProcessor.class.getClassLoader(),
				bean.getClass().getInterfaces(), new InvocationHandler() {
					@Override
					public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
						System.out.println("--=-- before");
						Object invoke = method.invoke(bean, args);
						return invoke;
					}
				});
	}
}
